import { Request } from './request';
import { requestWrapper } from './wrapper';
import type { RequestOptions, RequestPayload } from './types';

export function createRequest(options: RequestOptions) {
  const request = new Request(options);
  return function <T = any>(path: string, payload: RequestPayload) {
    return requestWrapper<T>(payload, (p) => {
      return request.send<T>(path, p);
    });
  }
}